#include "myapp.h"
#include "myhelper.h"

QString myApp::AppPath = "";
int myApp::DeskWidth =1024;
int myApp::DeskHeight = 768;

QString myApp::AppStyle = ":/image/silvery.css";
QString myApp::AppTitle = "火鸟证券网上证券交易分析系统";
int myApp::UserAccount=0;
int myApp::UserId=0;
bool myApp::AutoRun = false;
bool myApp::SaveAccount = true;
bool myApp::HideAccount = false;
QString myApp::AccountType = "客户号";
QString myApp::EncryptedProtocol = "核新加密";
QString myApp::DataServer = "Tencet";
QString myApp::MasterStationAddress = "火鸟证券（南京联通二）";

//读取配置文件
void myApp::ReadConfig()
{
    QString fileName = myApp::AppPath + "config.txt";
    //如果配置文件不存在,则以初始值继续运行
    if (!myHelper::FileIsExist(fileName)) {
        //对应中文转成正确的编码
        myApp::AppTitle = myApp::AppTitle.toLatin1();
        myApp::MasterStationAddress = myApp::MasterStationAddress.toLatin1();
        return;
    }

    QSettings *set = new QSettings(fileName, QSettings::IniFormat);

    set->beginGroup("AppConfig");
    myApp::AppTitle = set->value("AppTitle").toString();
    myApp::AppStyle = set->value("AppStyle").toString();
    myApp::UserAccount = set->value("UserAccount").toInt();
    myApp::UserId = set->value("UserId").toInt();
    myApp::AutoRun = set->value("AutoRun").toBool();
    myApp::SaveAccount = set->value("SaveAccount").toBool();
    myApp::HideAccount = set->value("HideAccount").toBool();
    myApp::AccountType = set->value("AccountType").toString();
    myApp::EncryptedProtocol = set->value("EncryptedProtocol").toString();
    myApp::DataServer = set->value("DataServer").toString();
    myApp::MasterStationAddress = set->value("MasterStationAddress").toString();
    set->endGroup();
}

//写入配置文件
void myApp::WriteConfig()
{
    QString fileName = myApp::AppPath + "config.txt";
    QSettings *set = new QSettings(fileName, QSettings::IniFormat);

    set->beginGroup("AppConfig");
    set->setValue("AppTitle", myApp::AppTitle);
    set->setValue("AppStyle", myApp::AppStyle);
    set->setValue("AutoRun", myApp::AutoRun);
    set->endGroup();
}

